﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//请先添加引用
namespace Maticsoft.DAL.Jobs
{
    /// <summary>
    /// 数据访问类Job_class。
    /// </summary>
    public class Job_class
    {
        public Job_class()
        { }
        #region  成员方法

      
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int classId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Job_class");
            strSql.Append(" where classId=@classId ");
            SqlParameter[] parameters = {
					new SqlParameter("@classId", SqlDbType.Int,4)};
            parameters[0].Value = classId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.Jobs.Job_class model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Job_class(");
            strSql.Append("className,classDesc)");
            strSql.Append(" values (");
            strSql.Append("@className,@classDesc)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@className", SqlDbType.NVarChar,50),
					new SqlParameter("@classDesc", SqlDbType.NVarChar,255)};
            parameters[0].Value = model.className;
            parameters[1].Value = model.classDesc;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Maticsoft.Model.Jobs.Job_class model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Job_class set ");
            strSql.Append("className=@className,");
            strSql.Append("classDesc=@classDesc");
            strSql.Append(" where classId=@classId ");
            SqlParameter[] parameters = {
					new SqlParameter("@classId", SqlDbType.Int,4),
					new SqlParameter("@className", SqlDbType.NVarChar,50),
					new SqlParameter("@classDesc", SqlDbType.NVarChar,255)};
            parameters[0].Value = model.classId;
            parameters[1].Value = model.className;
            parameters[2].Value = model.classDesc;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int classId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Job_class ");
            strSql.Append(" where classId=@classId ");
            SqlParameter[] parameters = {
					new SqlParameter("@classId", SqlDbType.Int,4)};
            parameters[0].Value = classId;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Jobs.Job_class GetModel(int classId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 classId,className,classDesc from Job_class ");
            strSql.Append(" where classId=@classId ");
            SqlParameter[] parameters = {
					new SqlParameter("@classId", SqlDbType.Int,4)};
            parameters[0].Value = classId;

            Maticsoft.Model.Jobs.Job_class model = new Maticsoft.Model.Jobs.Job_class();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["classId"].ToString() != "")
                {
                    model.classId = int.Parse(ds.Tables[0].Rows[0]["classId"].ToString());
                }
                model.className = ds.Tables[0].Rows[0]["className"].ToString();
                model.classDesc = ds.Tables[0].Rows[0]["classDesc"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select classId,className,classDesc ");
            strSql.Append(" FROM Job_class ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by classId,className ");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" classId,className,classDesc ");
            strSql.Append(" FROM Job_class ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Job_class";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

